﻿// -----------------------------------------------------------------------
// <copyright file="GetUserByIdQuery.cs">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com  andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Queries.Users
{
	using System.Linq;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Database.Dto;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Mappers;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.Model.Queries.Users;
	using Moveax.DataAccess.Cqrs.Highway.UnitTests.DataAccess.Queries;
	using Moveax.DataAccess.Cqrs.Highway.UnitTests.Model;

	internal class GetUserByIdQuery : QueryBaseClass, IGetUserByIdQuery
	{
		public GetUserByIdQuery(IDataSource dataSource)
			: base(dataSource)
		{
		}

		public User Execute(int userId, bool includeLinks)
		{
			var user = includeLinks ?
				this._dataSource.Set<UserDto>(p => p.Links).FirstOrDefault(p => p.Id == userId) :
				this._dataSource.Set<UserDto>().FirstOrDefault(p => p.Id == userId);

			return user.ToModel();
		}
	}
}